<script>
    function ajax_refresh_peer_reviews_table()
    {
        window.location = '';
    }

    function ajax_peer_review_modal(peer_review_id)
    {
        
        $('#add_review_btn').prop("disabled", true);
        $.ajax( '/publication/' + {{ publication.publication_id }} + '/peer_review_modal', {
            data: {
               'csrfmiddlewaretoken': '{{ csrf_token }}',
               'peer_review_id' : peer_review_id
            },
            type: 'post',
            success: function(result) {
               // success code execution here
               $('#ajax_modal_placeholder').html(result);
               $('#peer_review_modal').modal();
            },
            error: function(xhr,status,error) {
               // error code here
            },
            complete: function(xhr,status) {
               // completion code here
            }
        });
    }

    function ajax_save_peer_review(peer_review_id)
    {
        var url = '/publication/' + {{ publication.publication_id }} + '/save_peer_review';
        var marks = $('#id_marks').val();
        var text = $('#id_text').val();
    
        $.ajax( url, {
            data: {
               'csrfmiddlewaretoken': '{{ csrf_token }}',
               'peer_review_id': peer_review_id,
               'marks': marks,
               'text': text,
            },
            type: 'post',
            success: function(result) {
               if (result.status == 'success')
               {
                    $('#peer_review_modal').modal('hide');
                    ajax_refresh_peer_reviews_table();
               }
               else
               {
                    alert(result.message);
               }
            },
            error: function(xhr,status,error) {
               // error code here
            },
            complete: function(xhr,status) {
               // completion code here
            }
        });
    }

    function ajax_delete_peer_review(peer_review_id)
    {
        var url = '/publication/' + {{ publication.publication_id }} + '/delete_peer_review';
        $.ajax( url, {
            data: {
            'csrfmiddlewaretoken': '{{ csrf_token }}',
            'peer_review_id': peer_review_id,
        },
        type: 'post',
        success: function(result) {
            if (result.status == 'success')
            {
               ajax_refresh_peer_reviews_table();
            }
            else
            {
               alert(result.message);
            }
        },
        error: function(xhr,status,error) {
               // error code here
        },
        complete: function(xhr,status) {
               // completion code here
        }
    });
}

</script>